package com.ms.p2p.service.impl;

import com.ms.common.utils.MsDateUtils;
import com.ms.p2p.bean.PageBean;
import com.ms.p2p.dao.YueBaoLogDao;
import com.ms.p2p.entity.account.YuEbao;
import com.ms.p2p.entity.account.YuEbaoLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Description:活期宝操作记录
 */
@Service
@Transactional(readOnly = true)
public class YuEbaoLogServiceImpl{

	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int insert(YuEbao yuEbao, String type, BigDecimal money,
					  String remark, String addIp) {
		YuEbaoLog yuEbaoLog = new YuEbaoLog();
		yuEbaoLog.setUser_id(yuEbao.getUser_id());
		yuEbaoLog.setType(type);
		yuEbaoLog.setMoney(money);
		yuEbaoLog.setTotal(yuEbao.getTotal());
		yuEbaoLog.setYesterday_income(yuEbao.getYesterday_income());
		yuEbaoLog.setTotal_income(yuEbao.getTotal_income());
		yuEbaoLog.setRemark(remark);
		yuEbaoLog.setAddtime(MsDateUtils.getTime());
		yuEbaoLog.setAddip(addIp);
		return insert(yuEbaoLog);
	}

	@Autowired
	private YueBaoLogDao logDao;

	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public int insert(YuEbaoLog yuEbaoLog) {
		return logDao.insert(yuEbaoLog);
	}

	public List<Map<String, Object>> getPager(String userId, String userName,
			String logType, String begin_date, String end_date, PageBean page) {
		return logDao.getPager(userId, userName, logType, begin_date, end_date,
				page.getBegin(), page.getPageSize());
	}

	public Map<String, Object> cacuYesterDay(int userId) {
		return logDao.cacuYesterDay(userId);
	}

	public List<YuEbaoLog> findPager(Integer id, PageBean page) {
		return logDao.findPager(id, page.getBegin(), page.getPageSize());
	}

	public int findCount(Integer ide) {
		return logDao.findCount(ide);
	}

	public int getCount(String userId, String userName, String logType,
			String begin_date, String end_date) {

		return logDao.getCount(userId, userName, logType, begin_date, end_date);
	}

}
